﻿@{
    ViewBag.Title = "Common Command";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<ol class="breadcrumb">
    <li><a href="/Home/Home">Home</a></li>
    <li><a href="/Common/CommonIntoduction"> Sanelib Common</a></li>
    <li class="active">Service-Model Service</li>
</ol>
<div id="introduction">
    <h1 class="text-left">ModelService</h1>
    <p><strong>IModelService Interface</strong><br/>IModelservice Interface that defines one abstract method. CheckMemberRegistrationForm type Method have two parameter RegistrationForm type of form and validationResult type of ErrorResult which have return boolean type .
    <pre><code>public interface IModelService<br/>{<br/>bool CheckMemberRegistrationForm(RegistrationForm form, ErrorResult validationResult);<br/>}<br/></code></pre>
    the ModelService is extend by this IModelService from<strong>Common ClassLibrary </strong> in <strong>Service Project </strong> Show in Below. 
    <pre><code>public class ModelService : IModelService<br />{<br />private readonly IViewRepository&lt;memberview&gt; _memberViewRepository;<br />public ModelService(IViewRepository&lt;memberview&gt; memberViewRepository)<br />{<br />_memberViewRepository = memberViewRepository;<br />}<br />}</code></pre>
    This ModelService class has One Constructor that assign _memberView Repository to Type of MemberView.
    <br/>Model Service also implement CheckMemberRegistrationForm Method Check Registration Validation Show in Below.
    <pre><code>public bool CheckMemberRegistrationForm(RegistrationForm form, ErrorResult validationResult)<br />{<br />var userWithSameUsername = _memberViewRepository.GetByKey(Property.Of&lt;memberview&gt;(entity => entity.Name), form.Name);<br/>if (userWithSameUsername != null)<br/>validationResult.AddError("A user with the same username already exists in the system.", string.Empty);<br />var userWithSameEmail = _memberViewRepository.GetByKey(Property.Of&lt;memberview&gt;(entity => entity.Address), form.Email);<br/>if(userWithSameEmail != null)<br/>validationResult.AddError("A user with the same email address already exists in the system.", string.Empty);<br/>if(string.IsNullOrWhiteSpace(form.Code) || form.Code == null)<br/>validationResult.AddError("Code", " should not be empty.");<br/>if (string.IsNullOrWhiteSpace(form.Name) || form.Name == null)<br/>validationResult.AddError("Name", " should not be empty.");<br/>if (form.DateOfBirth > SystemTime.Now())<br/>validationResult.AddError("DateOfBirth", " is invalid.");<br/>if (string.IsNullOrWhiteSpace(form.Email) || form.Name == null || Regex.IsMatch(form.Email, @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"))<br/> validationResult.AddError("Email address ", " is invalid.");<br/>return validationResult.IsValid;<br/>}</code></pre>
    <p>Here,this Method  Check RegistrationForm Field like Member Register with Same Username or not and member Register with existing email or not.Member Register with same username that is show username is already existing  with ValidationResult and return validationResult type with boolean in MemberController.cs show in Below</p>
    <pre><code>if (!_modelService.CheckMemberRegistrationForm(form, validationResult))<br/>{<br/>return Content(validationResult);<br/>}<br/></code></pre>
</div>

        
        